package com.ruoyi.app.controller.common.controller;

import com.ruoyi.app.controller.common.service.ISysConfigService;
import com.ruoyi.common.annotation.ParseShopId;
import com.ruoyi.common.annotation.PassToken;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/index")
@Api(value = "公共", description = "公共模块")
public class IndexController extends BaseController {

    @Resource
    private ISysConfigService sysConfigService;

    @GetMapping("")
    @PassToken
    public AjaxResult index() {
        return success();
    }

    @ApiOperation(value = "获取配置", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "configKey", value = "配置的键值", required = true, dataTypeClass = String.class,paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "获取成功！"),
    })
    @GetMapping("/getConfig")
    @PassToken
    public AjaxResult getConfig(@ApiIgnore @ParseShopId Long shopId) {
        if (StringUtils.isEmpty(ServletUtils.getParameter("configKey"))) {
            return error("该配置不存在！");
        }
        String configKey = ServletUtils.getParameter("configKey");
        String configValue = sysConfigService.selectCustomerConfigByKey(configKey);
        return AjaxResult.success("获取成功！", configValue);
    }
}
